//异步请求
import axios from "axios";

import { Message } from 'element-ui';
//有两个参数context用于提交到matastion第二个是传递的参数
const actions = {

/**-------------------------------------------------通知公告--------------------------------------------- */
    //全部查询
    allnn(context,log){
        axios.post('http://127.0.0.1:7001/setup/NoticeAll',log).then(res =>{
            // console.log(log.status);
            // console.log(res.data.result);
             console.log(res);
            //console.log(context);
            //console.log(log)
            context.commit('allnn',res.data.result)
        })
    },


    //添加请求
    addnn(context,log){


        axios.post('http://127.0.0.1:7001/setup/NoticeAdd',log).then(res =>{
            // console.log(log.status);
            // console.log(res.data.result);
             console.log(res);
     
            //context.commit('allnn',res.data.result)
        }).then(()=> {
            actions.allnn(context,{status:1})
            Message({
                showClose: true,
                message: '添加成功',
                type: 'success'
              });
            
        })
    },

    //删除请求
    deletenn(context,log){

        let ddid = context.state.setupNnData[log]
        //let 
        ddid.status = 0
        axios.post('http://127.0.0.1:7001/setup/NoticeDelete',ddid).then(res =>{
            // console.log(log.status);
            // console.log(res.data.result);
             console.log(res);
     
            //context.commit('allnn',res.data.result)
        }).then(()=> {
            //刷新数据
            actions.allnn(context,{status:1})
            Message({
                showClose: true,
                message: '删除成功',
                type: 'success'
              });
        })
        //console.log(upid);

    },

    //修改请求
    updatenn(context,log){
        axios.post('http://127.0.0.1:7001/setup/NoticeUpdate',log).then(res =>{
            // console.log(log.status);
            // console.log(res.data.result);
             console.log(res);
     
            //context.commit('allnn',res.data.result)
        }).then(()=> {
            //刷新数据
            actions.allnn(context,{status:1})
            Message({
                showClose: true,
                message: '修改成功',
                type: 'success'
              });
        })
        //console.log(upid);
    },

    //搜索请求
    searchn(context,log){
        axios.get('http://127.0.0.1:7001/setup/NoticeLike?search='+log).then(res =>{
            // console.log(log.status);
            // console.log(res.data.result);
             console.log(res);
            //console.log(context);
            console.log(log)
            context.commit('allnn',res.data.result)
        })
    },


    /**-------------------------------------------------客服管理--------------------------------------------- */

    //查询全部客服
    csmall(context,log){
        axios.post('http://127.0.0.1:7001/setup/CustomerServiceAll',log).then(res =>{
            // console.log(log.status);
            // console.log(res.data.result);
             console.log(res);
            //console.log(context);
            //console.log(log)
            context.commit('allcsm',res.data.result)
        })

    },
    

    //添加时分组
    csmaddgroup(context,log){
        axios.post('http://127.0.0.1:7001/setup/CustomerServiceGroup',log).then(res =>{
             console.log(res);
            
        })
    },

    //添加客服
    csmadd(context,log){
        axios.post('http://127.0.0.1:7001/setup/CustomerServiceAdd',log).then(res =>{
      
             console.log(res);
  
        }).then(()=> {
      
            //添加后给客服分组
            actions.csmaddgroup(context,log)
            Message({
                showClose: true,
                message: log,
                type: 'success'
              });
        }).then(() => {
            //刷新数据
            actions.csmall(context,{status:1})
        })
        
    },
    

    //查看全部客服组
    csmgroup(context,log){
        axios.post('http://127.0.0.1:7001/setup/GroupAll',log).then(res =>{
           
             console.log(res);
    
            context.commit('groupcsm',res.data.result)
        })

    },
    //删除客服
    deletecsm(context,log){

        let ddid = context.state.setupCsmData[log]
        //let 
        ddid.status = 0
        axios.post('http://127.0.0.1:7001/setup/CustomerServiceDelete',ddid).then(res =>{
            // console.log(log.status);
            // console.log(res.data.result);
             console.log(res);
     
            //context.commit('allnn',res.data.result)
        }).then(()=> {
            //刷新数据
            actions.csmall(context,{status:1})
            Message({
                showClose: true,
                message: '删除成功',
                type: 'success'
              });
        })
        //console.log(upid);

    },
    updatecsm(context,log){
        axios.post('http://127.0.0.1:7001/setup/CustomerServiceUpdate',log).then(res =>{
            // console.log(log.status);
            // console.log(res.data.result);
             console.log(res);
     
            //context.commit('allnn',res.data.result)
        }).then(()=> {
            //刷新数据
            actions.csmall(context,{status:1})
            Message({
                showClose: true,
                message: '修改成功',
                type: 'success'
              });
        })
    },
    searchcsm(context,log){
        axios.get('http://127.0.0.1:7001/setup/CustomerServiceLike?search='+log).then(res =>{
             console.log(log);
            // console.log(res.data.result);
             console.log(res);

            //context.commit('allnn',res.data.result)
            context.commit('allcsm',res.data.result)
        })
    },
     /**-------------------------------------------------分组管理--------------------------------------------- */
     groupall(context,log){
        axios.post('http://127.0.0.1:7001/setup/GroupAll',log).then(res =>{
            // console.log(log.status);
            // console.log(res.data.result);
             console.log(res);
            //console.log(context);
            //console.log(log)
            context.commit('allgroup',res.data.result)
        })

     },
     groupadd(context,log){
        axios.post('http://127.0.0.1:7001/setup/GroupAdd',log).then(res =>{
            // console.log(log.status);
            // console.log(res.data.result);
             console.log(res);
            //console.log(context);
            //console.log(log)
            //context.commit('allgroup',res.data.result)
        }).then(() => {
            actions.groupall(context,{status:1})
            Message({
                showClose: true,
                message: '创建成功',
                type: 'success'
              });
        })
     },
     groupdelete(context,log){

        let ddid = context.state.setupGroupData[log]
        //let 
        ddid.status = 0
        axios.post('http://127.0.0.1:7001/setup/GroupDelete',ddid).then(res =>{
            // console.log(log.status);
            // console.log(res.data.result);
             console.log(res);
     
            //context.commit('allnn',res.data.result)
        }).then(()=> {
            //刷新数据
            actions.groupall(context,{status:1})
            Message({
                showClose: true,
                message: '删除成功',
                type: 'success'
              });
        })
     },
     groupupdate(context,log){
        axios.post('http://127.0.0.1:7001/setup/GroupUpdate',log).then(res =>{
            // console.log(log.status);
            // console.log(res.data.result);
             console.log(res);
     
            //context.commit('allnn',res.data.result)
        }).then(()=> {
            //刷新数据
            actions.groupall(context,{status:1})
            Message({
                showClose: true,
                message: '修改成功',
                type: 'success'
              });
        })
     },
     searchgroup(context,log){
        axios.get('http://127.0.0.1:7001/setup/GroupLike?search='+log).then(res =>{
             console.log(log);
            // console.log(res.data.result);
             console.log(res);

            //context.commit('allnn',res.data.result)
            context.commit('allgroup',res.data.result)
        })
    },

     /**-------------------------------------------------预设问题--------------------------------------------- */
     ppall(context,log){
        axios.post('http://127.0.0.1:7001/setup/ProblemAll',log).then(res =>{
            // console.log(log.status);
            // console.log(res.data.result);
             console.log(res);
            //console.log(context);
            //console.log(log)
            context.commit('allpp',res.data.result)
        })
     },
     ppadd(context,log){
        axios.post('http://127.0.0.1:7001/setup/ProblemAdd',log).then(res =>{
            // console.log(log.status);
            // console.log(res.data.result);
             console.log(res);
            //console.log(context);
            //console.log(log)
            //context.commit('allgroup',res.data.result)
        }).then(() => {
            actions.ppall(context,{status:1})
            Message({
                showClose: true,
                message: '添加成功',
                type: 'success'
              });
        })
     },
     ppupdate(context,log){
        axios.post('http://127.0.0.1:7001/setup/ProblemUpdate',log).then(res =>{
            // console.log(log.status);
            // console.log(res.data.result);
             console.log(res);
            //console.log(context);
            //console.log(log)
            //context.commit('allgroup',res.data.result)
        }).then(() => {
            actions.ppall(context,{status:1})
            Message({
                showClose: true,
                message: '修改成功',
                type: 'success'
              });
        })
     },
     ppdelete(context,log){

        let ddid = context.state.setupPpData[log]
        //let 
        console.log(ddid);
        ddid.status = 0
        axios.post('http://127.0.0.1:7001/setup/ProblemDelete',ddid).then(res =>{
            // console.log(log.status);
            // console.log(res.data.result);
             console.log(res);
     
            //context.commit('allnn',res.data.result)
        }).then(()=> {
            //刷新数据
            actions.ppall(context,{status:1})
            Message({
                showClose: true,
                message: '删除成功',
                type: 'success'
              });
        })
     },

     
     /**-------------------------------------------------黑名单--------------------------------------------- */
     blall(context,log){
        axios.post('http://127.0.0.1:7001/setup/BlackListAll',log).then(res =>{
            // console.log(log.status);
            // console.log(res.data.result);
             console.log(res);
            //console.log(context);
            //console.log(log)
            context.commit('allbl',res.data.result)
        })
     },
     bldelete(context,log){
        let ddid = context.state.setupBlData[log]
        //let 
        console.log(ddid);
        ddid.status = 0
        axios.post('http://127.0.0.1:7001/setup/BlackListDelete',ddid).then(res =>{
            // console.log(log.status);
            // console.log(res.data.result);
             console.log(res);
     
            //context.commit('allnn',res.data.result)
        }).then(()=> {
            //刷新数据
            actions.blall(context,{status:1})
            Message({
                showClose: true,
                message: '删除成功',
                type: 'success'
              });
        })
     },
     //搜索
     searchbl(context,log){
        axios.get('http://127.0.0.1:7001/setup/BlackListLike?search='+log).then(res =>{
           
           //context.commit('allnn',res.data.result)
           context.commit('allbl',res.data.result)
       })
     },
     /**---------------------------------------常用语----------------------------------------------- */
     allcwgroup(context,log){
        axios.post('http://127.0.0.1:7001/setup/CommonWordsGroup',log).then(res =>{
           console.log(res.data.result);
           console.log(log);
            //context.commit('allnn',res.data.result)
            context.commit('cwgroupall',res.data.result)
        })
     },
     allcw(context,log){
        axios.post('http://127.0.0.1:7001/setup/CommonWordsAll',log).then(res =>{
           
            //context.commit('allnn',res.data.result)
            context.commit('cwall',res.data.result)
        })
     }
}

export default actions